﻿using System.Collections.Generic;
using System.Linq;
using Grundy.Common;
using Grundy.Message;

namespace Grundy.CryptographicServices
{
    public class NodeIdentityComparer
    {
        private List<Identifier> _nodeRequiredIdentifiers;

        public NodeIdentityComparer(IdentifierCollection nodeIdentifiers)
        {
            _nodeRequiredIdentifiers = (nodeIdentifiers ?? new IdentifierCollection()).Where(i => !i.Ignore).ToList();
        }

        public bool Matches(IdentifierCollection identifierCollection)
        {
            var required = identifierCollection.Where(i => !i.Ignore).ToList();
            return _nodeRequiredIdentifiers.All(required.Contains) || required.All(_nodeRequiredIdentifiers.Contains);
        }
    }
}